﻿using PlaceOrder_Shared.Models.Trade;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace PlaceOrder_Client.Converters
{
    public class TradePriceMinConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var trades = value as IEnumerable<TradeHistoryRow>; // 假设Trade是你的数据模型
            if (trades != null&&trades.Count()>0)
            {
                double minTradePrice = (double)trades.Min(x => x.TradePrice);
                return minTradePrice-0.005;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class TradePriceMaxConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var trades = value as IEnumerable<TradeHistoryRow>; // 假设Trade是你的数据模型
            if (trades != null && trades.Count() > 0)
            {
                double maxTradePrice = (double)trades.Max(x => x.TradePrice);
                return maxTradePrice+0.005;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }



    public class TradeTimeMinConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var trades = value as IEnumerable<TradeHistoryRow>; // 假设Trade是你的数据模型
            if (trades != null && trades.Count() > 0)
            {
                DateTime minTradeTime = trades.Min(x => x.TradeDate);
                return minTradeTime;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class TradeTimeMaxConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var trades = value as IEnumerable<TradeHistoryRow>; // 假设Trade是你的数据模型
            if (trades != null && trades.Count() > 0)
            {
                DateTime maxTradeTime = trades.Max(x => x.TradeDate);
                return maxTradeTime;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
